
/*
 * Copyright (c) 2016. For Intelligent Group.
 */
package com.intelligent.ispc.export.grr;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.intelligent.ispc.common.utils.StringUtils;
import com.intelligent.ispc.constant.AppConstant;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import com.intelligent.ispc.core.dto.*;
import com.intelligent.ispc.foundation.poi.*;
import com.intelligent.ispc.utils.ExportLabelConstant;
import com.intelligent.ispc.utils.SummaryRuleStyle;
import org.apache.poi.ss.usermodel.CellStyle;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * fill data to sheet
 *
 * Created by Alice on 2016/9/15.
 * Update by cherry on 2016/09/26
 */
public class GrrExportWorker implements ExWorker {
    private SXSSFWorkbook workbook = new SXSSFWorkbook(SXSSFWorkbook.DEFAULT_WINDOW_SIZE);
    private List<ExSheet> sheets = new ArrayList<>();
    private ExSheet exSheet = new ExSheet();
    private List<ExCell> cellList = Lists.newLinkedList();

    private Map<String, CellStyle> mapRuleStyle = Maps.newHashMap();
    private Map<String, CellStyle> mapCellStyle = Maps.newHashMap();

    private Integer[] headIndex = new Integer[]{0, 0};
    private Integer[] dataIndex = new Integer[]{5, 1};
    private Integer[] dataIndexImage = new Integer[]{5, 6};
    private Integer currentRow = 0;
    private Double[] grrRules = new Double[3];

    /**
     * assemble data of GRR Summary table
     *
     * @param searchParams      param of table head
     * @param grrSummaryDtoList data of summary data
     * @param index             controling param when split accembly data
     */
    public void buildGrrSummary(Map<String, Object> searchParams, List<GrrSummaryDto> grrSummaryDtoList, int index) {
        mapCellStyle = CellStyleUtil.getStyle(this.getCurrentWorkbook());
        int digGrrNum = (int) searchParams.get("digGrrNum");

        if (sheets != null && sheets.size() < 1) {
            cellList.addAll(buildSummaryHead(searchParams));
        }
        cellList.addAll(buildSummaryContent(grrSummaryDtoList, index, digGrrNum));
        exSheet.setExCells(cellList);
        exSheet.setName(AppConstant.GRR_EXPORT_SUMMARY);
        if (sheets != null && sheets.size() < 1) {
            sheets.add(exSheet);
        }
    }

    /**
     * assemble data of GRR Summary and Detail table
     *
     * @param searchParams           param of table head
     * @param grrSummaryDtoList      summary data
     * @param grrExportResultDtoList detail data
     */
    public void buildSummaryAndDetail(Map<String, Object> searchParams, List<GrrSummaryDto> grrSummaryDtoList, List<GrrExportResultDto> grrExportResultDtoList) {

        mapCellStyle = CellStyleUtil.getStyle(this.getCurrentWorkbook());
        int digGrrNum = (int) searchParams.get("digGrrNum");
        String sigma = "";
        String model = "";
        List<ExCell> summaryHead = buildSummaryHead(searchParams);
        List<ExCell> summaryContent = buildSummaryAndDetailContent(grrSummaryDtoList, searchParams);
        cellList.addAll(summaryHead);
        cellList.addAll(summaryContent);
        exSheet.setExCells(cellList);
        sheets.add(exSheet);
        exSheet.setName(AppConstant.GRR_EXPORT_SUMMARY);
        cellList = null;
        exSheet = null;

        if (grrExportResultDtoList != null && !grrExportResultDtoList.isEmpty()) {
            if (searchParams.containsKey("sigma")) {
                sigma = searchParams.get("sigma") + "";
            }
            if (searchParams.containsKey("model")) {
                model = (String) searchParams.get("model");
            }

            int j = 0;
            for (int i = 0; i < grrSummaryDtoList.size(); i++) {
                if (j >= grrExportResultDtoList.size()) {
                    break;
                }
                String summaryItemName = grrSummaryDtoList.get(i).getItemName();
                String subItemName = grrExportResultDtoList.get(j).getGrrExportParamDto().getItemName();

                if (summaryItemName.equals(subItemName)) {
                    ExSheet exSheetItem = new ExSheet();
                    List<ExCell> itemsCellList = buildGRRTestItem(sigma, model, grrExportResultDtoList.get(j), digGrrNum);
                    String itemName = grrExportResultDtoList.get(j).getGrrExportParamDto().getItemName();
                    if (itemName.contains(":") || itemName.contains("[") || itemName.contains("]")
                            || itemName.contains("*") || itemName.contains("/") || itemName.contains("\\")
                            || itemName.contains("?") || itemName.contains(" ")) {
                        itemName = itemName.replaceAll(":", "_");
                        itemName = itemName.replace("[", "_");
                        itemName = itemName.replaceAll("]", "_");
                        itemName = itemName.replace("*", "_");
                        itemName = itemName.replaceAll("/", "_");
                        itemName = itemName.replace("\\", "_");
                        itemName = itemName.replace("?", "_");
                        itemName = itemName.replaceAll(" ", "_");
                    }
                    exSheetItem.setName(itemName);
                    exSheetItem.setIndex(i + 1);
                    exSheetItem.setExCells(itemsCellList);
                    sheets.add(exSheetItem);
                    j++;
                    exSheetItem = null;
                    itemsCellList = null;
                }
            }
        }
    }

    private List<ExCell> buildSummaryHead(Map<String, Object> searchParams) {
        List<ExCell> exCellList = Lists.newArrayList();
        String[] titleLabelsOne = ExportLabelConstant.EXPORT_SUMMARY_LABELS_ONE;
        String[] titleLabelsTwo = ExportLabelConstant.EXPORT_SUMMARY_LABELS_TWO;
        String[] summaryRules = ExportLabelConstant.EXPORT_SUMMARY_RULES;
        if (searchParams.containsKey("rule")) {
            String rule = ((String) searchParams.get("rule"));
            if (rule.length() > 1) {
                rule = rule.substring(1, rule.length() - 1);
                String[] rules = rule.split(",");
                for (int i = 0; i < rules.length; i++) {
                    if (i == 3) {
                        break;
                    }
                    grrRules[i] = new Double(rules[i]);
                }

                int n = 0;
                final int startCol = 9;
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + n, headIndex[1] + startCol},
                        "<" + rules[0] + "%", ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_params_text.toString())));
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + n, headIndex[1] + startCol + 1},
                        summaryRules[0], ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_params_Excellent.toString())));

                n++;
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + n, headIndex[1] + startCol},
                        rules[0] + "% ~ " + rules[1] + "%", ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_params_text.toString())));
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + n, headIndex[1] + startCol + 1},
                        summaryRules[1], ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_params_Adequate.toString())));

                n++;
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + n, headIndex[1] + startCol},
                        rules[1] + "% ~ " + rules[2] + "%", ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_params_text.toString())));
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + n, headIndex[1] + startCol + 1},
                        summaryRules[2], ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_params_Marginal.toString())));

                n++;
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + n, headIndex[1] + startCol},
                        ">" + rules[2] + "%", ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_params_text.toString())));
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + n, headIndex[1] + startCol + 1},
                        summaryRules[3], ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_params_Bad.toString())));
            }
        }

        for (int i = 0; i < titleLabelsOne.length; i++) {
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0], headIndex[1] + i}, titleLabelsOne[i], ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_title.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + 1, headIndex[1] + i}, titleLabelsTwo[i], ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_title.toString())));
        }
        titleLabelsOne = null;
        titleLabelsTwo = null;
        summaryRules = null;
        return exCellList;
    }

    private List<ExCell> buildSummaryContent(List<GrrSummaryDto> grrSummaryDtoList, int index, int digGrrNum) {
        List<ExCell> exCellList = Lists.newArrayList();
        mapRuleStyle = SummaryRuleStyle.getBackStyle(this.getCurrentWorkbook());
        int digGrrNumPer = (digGrrNum - 2) < 0 ? 0 : (digGrrNum - 2);
        int countIndex = 0;

        if (index != 0) {
            countIndex = index;
        }
        for (int i = 0; i < grrSummaryDtoList.size(); i++) {
            if (index == 0) {
                countIndex = i;
            }
            int n = 0;
            String name = grrSummaryDtoList.get(i).getItemName();
            String lsl = grrSummaryDtoList.get(i).getLsl();
            String usl = grrSummaryDtoList.get(i).getUsl();
            String tolerance = grrSummaryDtoList.get(i).getTolerance();
            String partVariation = grrSummaryDtoList.get(i).getPartVariation();
            String totalProcessVariation = grrSummaryDtoList.get(i).getTotalProcessVariation();
            String grr = grrSummaryDtoList.get(i).getGrr();
            String result = grrSummaryDtoList.get(i).getResult();
            if (("EXCELLENT").equals(result)) {
                result = ExportLabelConstant.EXPORT_SUMMARY_EXCELLENT;
            }

            if (("GOOD").equals(result)) {
                result = ExportLabelConstant.EXPORT_SUMMARY_ADEQUTE;
            }

            if (("ACCEPTABLE").equals(result)) {
                result = ExportLabelConstant.EXPORT_SUMMARY_MARGIMAL;
            }

            if (("RECTIFICATION").equals(result)) {
                result = ExportLabelConstant.EXPORT_SUMMARY_BAD;
            }
            String[] arr = {name, lsl, usl, tolerance, partVariation, totalProcessVariation, grr, result};
            for (int j = 0; j < arr.length; j++) {
                if (StringUtils.isBlankWithSpecialNumber(arr[j]) || ("Infinity").equals(arr[j])) {
                    arr[j] = "-";
                }
            }
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + countIndex + 2, headIndex[1] + n++}, (countIndex + 1) + "",
                    ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + countIndex + 2, headIndex[1] + n++}, arr[0],
                    ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_content_testItems_1.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + countIndex + 2, headIndex[1] + n++}, arr[1].equals("-") ? "-" : arr[1],
                    ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + countIndex + 2, headIndex[1] + n++}, arr[2].equals("-") ? "-" : arr[2],
                    ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + countIndex + 2, headIndex[1] + n++}, arr[3].equals("-") ? "-" : arr[3],
                    ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + countIndex + 2, headIndex[1] + n++}, arr[4].equals("-") ? "-" : formatDouble(Double.valueOf(arr[4]), digGrrNumPer) + "%",
                    ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + countIndex + 2, headIndex[1] + n++}, arr[5].equals("-") ? "-" : formatDouble(Double.valueOf(arr[5]), digGrrNumPer) + "%",
                    ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + countIndex + 2, headIndex[1] + n++}, arr[6].equals("-") ? "-" : formatDouble(Double.valueOf(arr[6]), digGrrNumPer) + "%",
                    ExCellType.TEXT, mapRuleStyle.get(result)));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + countIndex + 2, headIndex[1] + n++}, arr[7], ExCellType.TEXT, mapRuleStyle.get(result)));
            arr = null;
            if (index != 0) {
                countIndex++;
            }
        }

        return exCellList;
    }

    private List<ExCell> buildSummaryAndDetailContent(List<GrrSummaryDto> grrSummaryDtoList, Map<String, Object> searchParams) {
        List<ExCell> exCellList = Lists.newArrayList();
        String itemName = null;
        int digGrrNum = (int) searchParams.get("digGrrNum");
        int digGrrNumPer = (digGrrNum - 2) < 0 ? 0 : (digGrrNum - 2);

        mapRuleStyle = SummaryRuleStyle.getBackStyle(this.getCurrentWorkbook());

        for (int i = 0; i < grrSummaryDtoList.size(); i++) {
            int n = 0;
            String name = grrSummaryDtoList.get(i).getItemName();
            String lsl = grrSummaryDtoList.get(i).getLsl();
            String usl = grrSummaryDtoList.get(i).getUsl();
            String tolerance = grrSummaryDtoList.get(i).getTolerance();
            String partVariation = grrSummaryDtoList.get(i).getPartVariation();
            String totalProcessVariation = grrSummaryDtoList.get(i).getTotalProcessVariation();
            String grr = grrSummaryDtoList.get(i).getGrr();
            String result = grrSummaryDtoList.get(i).getResult();
            if (("EXCELLENT").equals(result)) {
                result = ExportLabelConstant.EXPORT_SUMMARY_EXCELLENT;
            }

            if (("GOOD").equals(result)) {
                result = ExportLabelConstant.EXPORT_SUMMARY_ADEQUTE;
            }

            if (("ACCEPTABLE").equals(result)) {
                result = ExportLabelConstant.EXPORT_SUMMARY_MARGIMAL;
            }

            if (("RECTIFICATION").equals(result)) {
                result = ExportLabelConstant.EXPORT_SUMMARY_BAD;
            }
            String[] arr = {name, lsl, usl, tolerance, partVariation, totalProcessVariation, grr, result};
            for (int j = 0; j < arr.length; j++) {
                if (StringUtils.isBlankWithSpecialNumber(arr[j]) || ("Infinity").equals(arr[j])) {
                    arr[j] = "-";
                }
            }
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + i + 2, headIndex[1] + n++}, (i + 1) + "",
                    ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_content.toString())));
            if (arr[6] == "-") {
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + i + 2, headIndex[1] + n++}, arr[0],
                        ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_content_testItems_1.toString())));
            } else {
                exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + i + 2, headIndex[1] + n++}, arr[0],
                        ExCellType.HYPERLINK.withCode(ExSheet.formatName(i + 1, name)), mapCellStyle.get(CellStyleType.summary_content_testItems.toString())));
            }
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + i + 2, headIndex[1] + n++}, arr[1].equals("-") ? "-" : arr[1],
                    ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + i + 2, headIndex[1] + n++}, arr[2].equals("-") ? "-" : arr[2],
                    ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + i + 2, headIndex[1] + n++}, arr[3].equals("-") ? "-" : arr[3],
                    ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + i + 2, headIndex[1] + n++}, arr[4].equals("-") ? "-" : formatDouble(Double.valueOf(arr[4]), digGrrNumPer) + "%",
                    ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + i + 2, headIndex[1] + n++}, arr[5].equals("-") ? "-" : formatDouble(Double.valueOf(arr[5]), digGrrNumPer) + "%",
                    ExCellType.TEXT, mapCellStyle.get(CellStyleType.summary_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + i + 2, headIndex[1] + n++}, arr[6].equals("-") ? "-" : formatDouble(Double.valueOf(arr[6]), digGrrNumPer) + "%",
                    ExCellType.TEXT, mapRuleStyle.get(result)));
            exCellList.add(ExUtil.fillToCell(new Integer[]{headIndex[0] + i + 2, headIndex[1] + n++}, arr[7], ExCellType.TEXT, mapRuleStyle.get(result)));
            arr = null;
        }
        return exCellList;
    }

    private List<ExCell> buildGRRTestItem(String sigma, String type, GrrExportResultDto grrExportResultDto, int digGrrNum) {
        List<ExCell> exCellList = Lists.newArrayList();
        List<ExCell> exCellParamList = buildTestItemGRRParam(grrExportResultDto.getGrrExportParamDto(), type);
        double trialCount = Double.valueOf(grrExportResultDto.getGrrExportParamDto().getTrialCount());
        List<ExCell> exCellGRRDataList = buildTestItemGRRData((int) trialCount, type, grrExportResultDto.getGrrViewDataDtos(), grrExportResultDto.getGrrStatisticDataDtoList(), digGrrNum);
        List<ExCell> exCellGRRAnovaList = buildTestItemGRRAnova(grrExportResultDto.getGrrAnovaDtoList(), digGrrNum);
        List<ExCell> exCellGRRSourceList = buildTestItemGRRSource(grrExportResultDto.getGrrSourceDtoList(), sigma, digGrrNum);
        List<ExCell> exCellGRRImagesList = buildTestItemGRRImages(grrExportResultDto.getImgPaths());
        exCellList.addAll(exCellParamList);
        exCellList.addAll(exCellGRRDataList);
        exCellList.addAll(exCellGRRAnovaList);
        exCellList.addAll(exCellGRRSourceList);
        exCellList.addAll(exCellGRRImagesList);
        exCellParamList = null;
        exCellGRRDataList = null;
        exCellGRRAnovaList = null;
        exCellGRRSourceList = null;
        exCellGRRImagesList = null;
        return exCellList;
    }

    private List<ExCell> buildTestItemGRRParam(GrrExportParamDto grrExportParamDto, String type) {
        List<ExCell> exCellList = Lists.newArrayList();

        String name = grrExportParamDto.getItemName() == null ? "-" : grrExportParamDto.getItemName();
        String usl = grrExportParamDto.getUsl() == null ? "-" : grrExportParamDto.getUsl();
        String lsl = grrExportParamDto.getLsl() == null ? "-" : grrExportParamDto.getLsl();
        String tolerance = grrExportParamDto.getTolerance() == null ? "-" : grrExportParamDto.getTolerance();
        String operatorCount = grrExportParamDto.getOperatorCount() == null ? "-" : grrExportParamDto.getOperatorCount();
        String snCount = grrExportParamDto.getSnCount() == null ? "-" : grrExportParamDto.getSnCount();
        String trialCount = grrExportParamDto.getTrialCount() == null ? "-" : grrExportParamDto.getTrialCount();
        String time = grrExportParamDto.getExportTime() == null ? "-" : grrExportParamDto.getExportTime();
        String performedBy = grrExportParamDto.getPerformedBy() == null ? "-" : grrExportParamDto.getPerformedBy();

        exCellList.add(ExUtil.fillToCell(new Integer[]{1, 1}, "Test Item", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_l_1.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{1, 2}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_l_2.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{2, 1}, name, ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_l_3.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{2, 2}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_l_4.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{3, 1}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_l_5.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{3, 2}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_l_6.toString())));

        exCellList.add(ExUtil.fillToCell(new Integer[]{1, 3}, "USL", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_m_1.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{1, 4}, usl, ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_m_2.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{2, 3}, "LSL", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_m_1.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{2, 4}, lsl, ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_m_2.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{3, 3}, "Tolerance", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_m_3.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{3, 4}, tolerance, ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_m_4.toString())));

        if (("NORMAL").equals(type)) {
            type = "Appraisers";
        }
        exCellList.add(ExUtil.fillToCell(new Integer[]{1, 5}, "Number of " + type + " = ", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_r_1.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{2, 5}, "Number of Parts = ", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_r_1.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{3, 5}, "Number of Trials = ", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_r_1.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{1, 6}, operatorCount, ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_r_5.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{2, 6}, snCount, ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_r_5.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{3, 6}, trialCount, ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_r_6.toString())));

        exCellList.add(ExUtil.fillToCell(new Integer[]{1, 7}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_r_3.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{1, 8}, "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_r_4.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{2, 7}, "Date: ", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_r_1.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{3, 7}, "Performed By: ", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_r_1.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{2, 8}, time, ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_r_2.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{3, 8}, performedBy, ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_param_r_2.toString())));
        return exCellList;
    }

    private List<ExCell> buildTestItemGRRData(int trialCount, String type, List<GrrViewDataDto> grrDataDtoList, List<GrrStatisticDataDto> grrStatisticDataDtoList, int digGrrNum) {
        List<ExCell> exCellList = Lists.newArrayList();

        if (grrDataDtoList.size() > 0) {
            int count = grrDataDtoList.size() / trialCount;
            int cursor = 0;
            int n = 0;

            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                    type, ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_title.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                    "Trial", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_title.toString())));
            for (int k = 0; k < grrDataDtoList.get(0).getColValueDtoList().size(); k++) {
                String key = grrDataDtoList.get(0).getColValueDtoList().get(k).getKey();
                exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                        key, ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_title.toString())));
            }
            currentRow++;

            for (int i = 0; i < count; i++) {
                int m = 0;
                for (int j = cursor; j < cursor + trialCount; j++) {
                    GrrViewDataDto grrDataDto = grrDataDtoList.get(j);
                    m = 0;
                    exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + m++},
                            grrDataDto.getOperator(), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_operator.toString())));
                    exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + m++},
                            grrDataDto.getTrial(), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_trial.toString())));
                    for (int k = 0; k < grrDataDto.getColValueDtoList().size(); k++) {
                        String value = String.valueOf(grrDataDto.getColValueDtoList().get(k).getValue());
                        if (StringUtils.isBlankWithSpecialNumber(value) || ("Infinity").equals(value)) {
                            value = "-";
                        }
                        exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + m++},
                                ("-").equals(value) ? value : formatDouble(Double.valueOf(value), digGrrNum), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_data.toString())));
                    }
                    currentRow++;
                    grrDataDto = null;
                }

                GrrStatisticDataDto grrStatisticDataDto = grrStatisticDataDtoList.get(i);
                m = 0;
                String rangeValue = grrStatisticDataDto.getRang();
                if (StringUtils.isBlankWithSpecialNumber(rangeValue) || ("Infinity").equals(rangeValue)) {
                    rangeValue = "-";
                }
                exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + m++},
                        ("-").equals(rangeValue) ? rangeValue : formatDouble(Double.valueOf(rangeValue), digGrrNum),
                        ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_rangeData.toString())));
                exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + m++},
                        "Range", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_rangeName.toString())));
                for (int i1 = 0; i1 < grrStatisticDataDto.getRangList().size(); i1++) {
                    String rValue = String.valueOf(grrStatisticDataDto.getRangList().get(i1).getValue());
                    if (StringUtils.isBlankWithSpecialNumber(rValue) || ("Infinity").equals(rValue)) {
                        rValue = "-";
                    }
                    exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + m++},
                            ("-").equals(rValue) ? rValue : formatDouble(Double.valueOf(rValue), digGrrNum),
                            ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_rangeData.toString())));
                }
                currentRow++;
                String meanValue = grrStatisticDataDto.getMean();
                if (StringUtils.isBlankWithSpecialNumber(meanValue) || ("Infinity").equals(meanValue)) {
                    meanValue = "-";
                }
                m = 0;
                exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + m++},
                        ("-").equals(meanValue) ? meanValue : formatDouble(Double.valueOf(meanValue), digGrrNum),
                        ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_avgData.toString())));
                exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + m++},
                        "AVG", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_avgName.toString())));
                for (int i1 = 0; i1 < grrStatisticDataDto.getMeanList().size(); i1++) {
                    String mValue = String.valueOf(grrStatisticDataDto.getMeanList().get(i1).getValue());
                    if (StringUtils.isBlankWithSpecialNumber(mValue) || ("Infinity").equals(mValue)) {
                        mValue = "-";
                    }
                    exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + m++},
                            ("-").equals(mValue) ? mValue : formatDouble(Double.valueOf(mValue), digGrrNum),
                            ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_avgData.toString())));
                }
                currentRow++;
                cursor += trialCount;
                grrStatisticDataDto = null;
            }

            int size = grrStatisticDataDtoList.size();
            GrrStatisticDataDto grrStatisticDataTotalDto = grrStatisticDataDtoList.get(size - 1);
            List<KeyValueDto> totalMeanList = grrStatisticDataTotalDto.getTotalMeanList();
            List<KeyValueDto> totalRangList = grrStatisticDataTotalDto.getTotalRangList();
            n = 0;

            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n},
                    "Part Range", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_totalName.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow + 1, dataIndex[1] + n},
                    "Part AVGS", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_totalName.toString())));
            n++;

            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n},
                    "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_totalName.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow + 1, dataIndex[1] + n},
                    "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_totalName.toString())));
            n++;

            for (int i = 0; i < totalMeanList.size(); i++) {
                String totalRange = String.valueOf(totalRangList.get(i).getValue());
                if (StringUtils.isBlankWithSpecialNumber(totalRange) || ("Infinity").equals(totalRange)) {
                    totalRange = "-";
                }
                String totalMean = String.valueOf(totalMeanList.get(i).getValue());
                if (StringUtils.isBlankWithSpecialNumber(totalMean) || ("Infinity").equals(totalMean)) {
                    totalMean = "-";
                }
                exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n},
                        ("-").equals(totalRange) ? totalRange : formatDouble(Double.valueOf(totalRange), digGrrNum), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_rangeData.toString())));
                exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow + 1, dataIndex[1] + n},
                        ("-").equals(totalMean) ? totalMean : formatDouble(Double.valueOf(totalMean), digGrrNum), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSn_rangeData.toString())));
                n++;
            }
            currentRow += 3;
            grrStatisticDataTotalDto = null;
            totalMeanList = null;
            totalRangList = null;
        }
        return exCellList;
    }

    private List<ExCell> buildTestItemGRRAnova(List<GrrAnovaDto> grrAnovaDtoList, int digGrrNum) {
        List<ExCell> exCellList = Lists.newArrayList();
        String[] anovaTitle = ExportLabelConstant.EXPORT_ANOVA_LABELS;
        int n = 0;
        for (int i = 0; i < anovaTitle.length; i++) {
            CellStyle style = mapCellStyle.get(CellStyleType.testItems_tbAnova_title_horizonal_m.toString());
            if (i == 0) {
                style = mapCellStyle.get(CellStyleType.testItems_tbAnova_title_horizonal_l.toString());
            }
            if (i == anovaTitle.length - 1) {
                style = mapCellStyle.get(CellStyleType.testItems_tbAnova_title_horizonal_r.toString());
            }
            if (i == 0) {
                exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, anovaTitle[i], ExCellType.TEXT, style));
                exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, style));
            } else {
                exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, anovaTitle[i], ExCellType.TEXT, style));
            }
            style = null;
        }
        currentRow++;

        for (int i = 0; i < grrAnovaDtoList.size(); i++) {
            n = 0;
            String keyValue = grrAnovaDtoList.get(i).getKeyValue();
            String dfValue = grrAnovaDtoList.get(i).getDfValue();
            String ssValue = grrAnovaDtoList.get(i).getSsValue();
            String msValue = grrAnovaDtoList.get(i).getMsValue();
            String fValue = grrAnovaDtoList.get(i).getfValue();
            String probFValue = grrAnovaDtoList.get(i).getProbFValue();
            String[] arr = {keyValue, dfValue, ssValue, msValue, fValue, probFValue};
            for (int j = 0; j < arr.length; j++) {
                if (StringUtils.isBlankWithSpecialNumber(arr[j]) || ("Infinity").equals(arr[j])) {
                    arr[j] = "-";
                }
            }
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                    arr[0], ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbAnova_title_vertical.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                    "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbAnova_title_vertical.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                    arr[1].equals("-") ? "-" : formatDouble(Double.valueOf(arr[1]), digGrrNum), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbAnova_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                    arr[2].equals("-") ? "-" : formatDouble(Double.valueOf(arr[2]), digGrrNum), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbAnova_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                    arr[3].equals("-") ? "-" : formatDouble(Double.valueOf(arr[3]), digGrrNum), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbAnova_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                    arr[4].equals("-") ? "-" : formatDouble(Double.valueOf(arr[4]), digGrrNum), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbAnova_content.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                    arr[5].equals("-") ? "-" : formatDouble(Double.valueOf(arr[5]), digGrrNum), ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbAnova_content.toString())));
            currentRow++;
            arr = null;
        }

        currentRow++;
        anovaTitle = null;
        return exCellList;
    }

    private List<ExCell> buildTestItemGRRSource(List<GrrSourceDto> grrSourceDtoList, String sigama, int digGrrNum) {
        List<ExCell> exCellList = Lists.newArrayList();
        String[] sourceTitle = ExportLabelConstant.EXPORT_SOURCE_LABELS;
        String categories = ExportLabelConstant.EXPORT_GRR_ITEM_CATEGORIES;
        int n = 0;

        exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                "Process of Distribution Width in Sigma's =  ", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSource_params_name.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSource_params_name.toString())));
        for (int i = 0; i < sourceTitle.length - 2; i++) {
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                    "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSource_params_name.toString())));
        }
        exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + 7},
                sigama, ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSource_params_value.toString())));
        currentRow++;
        n = 0;

        for (int i = 0; i < sourceTitle.length; i++) {
            String title = sourceTitle[i];
            if (i == 3) {
                title = sigama + " " + title;
            }

            CellStyle styleTitle = mapCellStyle.get(CellStyleType.testItems_tbSource_title_horizonal_m.toString());
            if (i == 0) {
                styleTitle = mapCellStyle.get(CellStyleType.testItems_tbSource_title_horizonal_l.toString());
            }
            if (i == sourceTitle.length - 1) {
                styleTitle = mapCellStyle.get(CellStyleType.testItems_tbSource_title_horizonal_r.toString());
            }
            if (i == 0) {
                exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, title, ExCellType.TEXT, styleTitle));
                exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, styleTitle));
            } else {
                exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, title, ExCellType.TEXT, styleTitle));
            }
            styleTitle = null;
        }

        int digGrrNumPer = (digGrrNum - 2) < 0 ? 0 : (digGrrNum - 2);
        currentRow++;
        for (int i = 0; i < grrSourceDtoList.size(); i++) {
            n = 0;
            String keyValue = grrSourceDtoList.get(i).getKeyValue();
            String variation = grrSourceDtoList.get(i).getVariation();
            String sigma = grrSourceDtoList.get(i).getSigma();
            String xSigma = grrSourceDtoList.get(i).getxSigma();
            String contribution = grrSourceDtoList.get(i).getContribution();
            String totalVariation = grrSourceDtoList.get(i).getTotalVariation();
            String tolerance = grrSourceDtoList.get(i).getTolerance();
            String[] arr = {keyValue, variation, sigma, xSigma, contribution, totalVariation, tolerance};
            for (int j = 0; j < arr.length; j++) {
                if (StringUtils.isBlankWithSpecialNumber(arr[j]) || ("Infinity").equals(arr[j])) {
                    arr[j] = "-";
                }
            }
            CellStyle style = mapCellStyle.get(CellStyleType.testItems_tbSource_content.toString());
            CellStyle grrStyle = mapRuleStyle.get(ExportLabelConstant.EXPORT_SUMMARY_EXCELLENT);
            if (("Appraisers").equals(keyValue) || ("Appraisers*Parts").equals(keyValue)) {
                style = mapCellStyle.get(CellStyleType.testItems_tbSource_content.toString());
            }

            if (("Gage R&R").equals(arr[0]) && grrRules.length >= 3 && !("-").equals(arr[6])) {
                if (Double.valueOf(arr[6]) <= grrRules[0]) {
                    grrStyle = mapRuleStyle.get(ExportLabelConstant.EXPORT_SUMMARY_EXCELLENT);
                }

                if (Double.valueOf(arr[6]) > grrRules[0] && Double.valueOf(arr[6]) <= grrRules[1]) {
                    grrStyle = mapRuleStyle.get(ExportLabelConstant.EXPORT_SUMMARY_ADEQUTE);
                }

                if (Double.valueOf(arr[6]) > grrRules[1] && Double.valueOf(arr[6]) <= grrRules[2]) {
                    grrStyle = mapRuleStyle.get(ExportLabelConstant.EXPORT_SUMMARY_MARGIMAL);
                }

                if (Double.valueOf(arr[6]) > grrRules[2]) {
                    grrStyle = mapRuleStyle.get(ExportLabelConstant.EXPORT_SUMMARY_BAD);
                }
            }

            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                    arr[0], ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSource_title_vertical.toString())));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++}, "", ExCellType.TEXT, style));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                    arr[1].equals("-") ? "-" : formatDouble(Double.valueOf(arr[1]), digGrrNum), ExCellType.TEXT, style));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                    arr[2].equals("-") ? "-" : formatDouble(Double.valueOf(arr[2]), digGrrNum), ExCellType.TEXT, style));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                    arr[3].equals("-") ? "-" : formatDouble(Double.valueOf(arr[3]), digGrrNum), ExCellType.TEXT, style));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                    arr[4].equals("-") ? "-" : formatDouble(Double.valueOf(arr[4]), digGrrNumPer) + "%", ExCellType.TEXT, style));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                    arr[5].equals("-") ? "-" : formatDouble(Double.valueOf(arr[5]), digGrrNumPer) + "%", ExCellType.TEXT, style));
            exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                    arr[6].equals("-") ? "-" : formatDouble(Double.valueOf(arr[6]), digGrrNumPer) + "%", ExCellType.TEXT, ("Gage R&R").equals(arr[0]) ? grrStyle : style));
            currentRow++;
            arr = null;
            style = null;
            grrStyle = null;
        }
        currentRow++;
        n = 0;

        String distincCategories = "-";
        if (!grrSourceDtoList.isEmpty()) {
            int size = grrSourceDtoList.size();
            distincCategories = grrSourceDtoList.get(size - 1).getDistincCategories();
        }
        exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                categories, ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSource_categoriesName.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSource_categoriesName.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSource_categoriesName.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSource_categoriesName.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                distincCategories, ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSource_categoriesValue.toString())));
        exCellList.add(ExUtil.fillToCell(new Integer[]{dataIndex[0] + currentRow, dataIndex[1] + n++},
                "", ExCellType.TEXT, mapCellStyle.get(CellStyleType.testItems_tbSource_categoriesValue.toString())));
        currentRow++;
        sourceTitle = null;
        return exCellList;
    }

    private List<ExCell> buildTestItemGRRImages(List<String> imgPaths) {
        List<ExCell> exCellList = Lists.newArrayList();
        final int n = 5;
        final int k = 4;
        final int m = 16;
        currentRow++;
        exCellList.add(ExUtil.fillToCell(new Integer[]{0, 0, AppConstant.EXPORT_IMG_WEIGHT, AppConstant.EXPORT_IMG_HEIGHT,
                dataIndex[1], dataIndex[0] + currentRow, dataIndex[1] + n, dataIndex[0] + currentRow + m}, imgPaths.get(0), ExCellType.IMAGE));
        exCellList.add(ExUtil.fillToCell(new Integer[]{0, 0, AppConstant.EXPORT_IMG_WEIGHT, AppConstant.EXPORT_IMG_HEIGHT,
                dataIndexImage[1], dataIndexImage[0] + currentRow, dataIndexImage[1] + k, dataIndexImage[0] + currentRow + m}, imgPaths.get(1), ExCellType.IMAGE));
        currentRow += m + 2;
        exCellList.add(ExUtil.fillToCell(new Integer[]{0, 0, AppConstant.EXPORT_IMG_WEIGHT, AppConstant.EXPORT_IMG_HEIGHT,
                dataIndex[1], dataIndex[0] + currentRow, dataIndex[1] + n, dataIndex[0] + currentRow + m}, imgPaths.get(2), ExCellType.IMAGE));
        exCellList.add(ExUtil.fillToCell(new Integer[]{0, 0, AppConstant.EXPORT_IMG_WEIGHT, AppConstant.EXPORT_IMG_HEIGHT,
                dataIndexImage[1], dataIndexImage[0] + currentRow, dataIndexImage[1] + k, dataIndexImage[0] + currentRow + m}, imgPaths.get(3), ExCellType.IMAGE));
        currentRow += m + 2;
        exCellList.add(ExUtil.fillToCell(new Integer[]{0, 0, AppConstant.EXPORT_IMG_WEIGHT, AppConstant.EXPORT_IMG_HEIGHT,
                dataIndex[1], dataIndex[0] + currentRow, dataIndex[1] + n, dataIndex[0] + currentRow + m}, imgPaths.get(4), ExCellType.IMAGE));
        exCellList.add(ExUtil.fillToCell(new Integer[]{0, 0, AppConstant.EXPORT_IMG_WEIGHT, AppConstant.EXPORT_IMG_HEIGHT,
                dataIndexImage[1], dataIndexImage[0] + currentRow, dataIndexImage[1] + k, dataIndexImage[0] + currentRow + m}, imgPaths.get(5), ExCellType.IMAGE));
        currentRow = 0;
        return exCellList;
    }


    private String formatDouble(Double str, int dig) {
        return String.format("%." + dig + "f", str);
    }


    @Override
    public SXSSFWorkbook getCurrentWorkbook() {
        return workbook;
    }


    @Override
    public List<ExSheet> getSheets() {
        return sheets;
    }
}